home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / CronVixie2.1 / cron.h < prev    next >
C/C++ Source or Header  |  1995-06-12  |  7KB  |  261 lines

  1. /* cron.h - header for vixie's cron
  2.  *
  3.  * $Header: cron.h,v 2.1 90/07/18 00:23:47 vixie Exp $
  4.  * $Source: /jove_u3/vixie/src/cron/RCS/cron.h,v $
  5.  * $Revision: 2.1 $
  6.  * $Log:    cron.h,v $
  7.  * Revision 2.1  90/07/18  00:23:47  vixie
  8.  * Baseline for 4.4BSD release
  9.  * 
  10.  * Revision 2.0  88/12/10  04:57:39  vixie
  11.  * V2 Beta
  12.  * 
  13.  * Revision 1.2  88/11/29  13:05:46  vixie
  14.  * seems to work on Ultrix 3.0 FT1
  15.  * 
  16.  * Revision 1.1  88/11/14  12:27:49  vixie
  17.  * Initial revision
  18.  * 
  19.  * Revision 1.4  87/05/02  17:33:08  paul
  20.  * baseline for mod.sources release
  21.  *
  22.  * vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley]
  23.  * vix 30dec86 [written]
  24.  */
  25.  
  26. /* Copyright 1988,1990 by Paul Vixie
  27.  * All rights reserved
  28.  *
  29.  * Distribute freely, except: don't remove my name from the source or
  30.  * documentation (don't take credit for my work), mark your changes (don't
  31.  * get me blamed for your possible bugs), don't alter or remove this
  32.  * notice.  May be sold if buildable source is provided to buyer.  No
  33.  * warrantee of any kind, express or implied, is included with this
  34.  * software; use at your own risk, responsibility for damages (if any) to
  35.  * anyone resulting from the use of this software rests entirely with the
  36.  * user.
  37.  *
  38.  * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
  39.  * I'll try to keep a version up to date.  I can be reached as follows:
  40.  * Paul Vixie, 329 Noe Street, San Francisco, CA, 94114, (415) 864-7013,
  41.  * paul@vixie.sf.ca.us || {hoptoad,pacbell,decwrl,crash}!vixie!paul
  42.  */
  43.  
  44. #ifndef    _CRON_FLAG
  45. #define    _CRON_FLAG
  46.  
  47. #include <stdio.h>
  48. #include <ctype.h>
  49. #include <bitstring.h>
  50. #include <sys/types.h>
  51. #include <sys/stat.h>
  52.  
  53. #include "config.h"
  54.  
  55.     /* these are really immutable, and are
  56.      *   defined for symbolic convenience only
  57.      * TRUE, FALSE, and ERR must be distinct
  58.      */
  59. #define TRUE        1
  60. #define FALSE        0
  61.     /* system calls return this on success */
  62. #define OK        0
  63.     /*   or this on error */
  64. #define ERR        (-1)
  65.  
  66.     /* meaningless cookie for smart compilers that will pick their
  67.      * own register variables; this makes the code neater.
  68.      */
  69. #define    local        /**/
  70.  
  71.     /* turn this on to get '-x' code */
  72. #ifndef DEBUGGING
  73. #define DEBUGGING    FALSE
  74. #endif
  75.  
  76. #define READ_PIPE    0    /* which end of a pipe pair do you read? */
  77. #define WRITE_PIPE    1    /*   or write to? */
  78. #define STDIN        0    /* what is stdin's file descriptor? */
  79. #define STDOUT        1    /*   stdout's? */
  80. #define STDERR        2    /*   stderr's? */
  81. #define ERROR_EXIT    1    /* exit() with this will scare the shell */
  82. #define    OK_EXIT        0    /* exit() with this is considered 'normal' */
  83. #define    MAX_FNAME    100    /* max length of internally generated fn */
  84. #define    MAX_COMMAND    1000    /* max length of internally generated cmd */
  85. #define    MAX_ENVSTR    1000    /* max length of envvar=value\0 strings */
  86. #define    MAX_TEMPSTR    100    /* obvious */
  87. #define    MAX_UNAME    20    /* max length of username, should be overkill */
  88. #define    ROOT_UID    0    /* don't change this, it really must be root */
  89. #define    ROOT_USER    "root"    /* ditto */
  90.  
  91.                 /* NOTE: these correspond to DebugFlagNames,
  92.                  *    defined below.
  93.                  */
  94. #define    DEXT        0x0001    /* extend flag for other debug masks */
  95. #define    DSCH        0x0002    /* scheduling debug mask */
  96. #define    DPROC        0x0004    /* process control debug mask */
  97. #define    DPARS        0x0008    /* parsing debug mask */
  98. #define    DLOAD        0x0010    /* database loading debug mask */
  99. #define    DMISC        0x0020    /* misc debug mask */
  100. #define    DTEST        0x0040    /* test mode: don't execute any commands */
  101.  
  102.                 /* the code does not depend on any of vfork's
  103.                  * side-effects; it just uses it as a quick
  104.                  * fork-and-exec.
  105.                  */
  106. #if defined(BSD)
  107. # define VFORK        vfork
  108. #endif
  109. #if defined(ATT)
  110. # define VFORK        fork
  111. #endif
  112.  
  113. #define    CRON_TAB(u)    "%s/%s", SPOOL_DIR, u
  114. #define    REG        register
  115. #define    PPC_NULL    ((char **)NULL)
  116.  
  117. #ifndef MAXHOSTNAMELEN
  118. #define MAXHOSTNAMELEN 64
  119. #endif
  120.  
  121. #define    Skip_Blanks(c, f) \
  122.             while (c == '\t' || c == ' ') \
  123.                 c = get_char(f);
  124.  
  125. #define    Skip_Nonblanks(c, f) \
  126.             while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \
  127.                 c = get_char(f);
  128.  
  129. #define    Skip_Line(c, f) \
  130.             do {c = get_char(f);} while (c != '\n' && c != EOF);
  131.  
  132. #if DEBUGGING
  133. # define Debug(mask, message) \
  134.             if ( (DebugFlags & (mask) ) == (mask) ) \
  135.                 printf message;
  136. #else /* !DEBUGGING */
  137. # define Debug(mask, message) \
  138.             ;
  139. #endif /* DEBUGGING */
  140.  
  141. #define    MkLower(ch)    (isupper(ch) ? tolower(ch) : ch)
  142. #define    MkUpper(ch)    (islower(ch) ? toupper(ch) : ch)
  143. #define    Set_LineNum(ln)    {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \
  144.              LineNumber = ln; \
  145.             }
  146.  
  147. #define    FIRST_MINUTE    0
  148. #define    LAST_MINUTE    59
  149. #define    MINUTE_COUNT    (LAST_MINUTE - FIRST_MINUTE + 1)
  150.  
  151. #define    FIRST_HOUR    0
  152. #define    LAST_HOUR    23
  153. #define    HOUR_COUNT    (LAST_HOUR - FIRST_HOUR + 1)
  154.  
  155. #define    FIRST_DOM    1
  156. #define    LAST_DOM    31
  157. #define    DOM_COUNT    (LAST_DOM - FIRST_DOM + 1)
  158.  
  159. #define    FIRST_MONTH    1
  160. #define    LAST_MONTH    12
  161. #define    MONTH_COUNT    (LAST_MONTH - FIRST_MONTH + 1)
  162.  
  163. /* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */
  164. #define    FIRST_DOW    0
  165. #define    LAST_DOW    7
  166. #define    DOW_COUNT    (LAST_DOW - FIRST_DOW + 1)
  167.  
  168.             /* each user's crontab will be held as a list of
  169.              * the following structure.
  170.              *
  171.              * These are the cron commands.
  172.              */
  173.  
  174. typedef    struct    _entry
  175.     {
  176.         struct _entry    *next;
  177.         char        *cmd;
  178.         bitstr_t    bit_decl(minute, MINUTE_COUNT);
  179.         bitstr_t    bit_decl(hour,   HOUR_COUNT);
  180.         bitstr_t    bit_decl(dom,    DOM_COUNT);
  181.         bitstr_t    bit_decl(month,  MONTH_COUNT);
  182.         bitstr_t    bit_decl(dow,    DOW_COUNT);
  183.         int        flags;
  184. # define    DOM_STAR    0x1
  185. # define    DOW_STAR    0x2
  186. # define    WHEN_REBOOT    0x4
  187.     }
  188.     entry;
  189.  
  190.             /* the crontab database will be a list of the
  191.              * following structure, one element per user.
  192.              *
  193.              * These are the crontabs.
  194.              */
  195.  
  196. typedef    struct    _user
  197.     {
  198.         struct _user    *next, *prev;    /* links */
  199.         int        uid;        /* uid from passwd file */
  200.         int        gid;        /* gid from passwd file */
  201.         char        **envp;        /* environ for commands */
  202.         time_t        mtime;        /* last modtime of crontab */
  203.         entry        *crontab;    /* this person's crontab */
  204.     }
  205.     user;
  206.  
  207. typedef    struct    _cron_db
  208.     {
  209.         user        *head, *tail;    /* links */
  210.         time_t        mtime;        /* last modtime on spooldir */
  211.     }
  212.     cron_db;
  213.  
  214.                 /* in the C tradition, we only create
  215.                  * variables for the main program, just
  216.                  * extern them elsewhere.
  217.                  */
  218.  
  219. #ifdef MAIN_PROGRAM
  220.  
  221. # if !defined(LINT) && !defined(lint)
  222.         static char *copyright[] = {
  223.             "@(#) Copyright (C) 1988, 1989, 1990 by Paul Vixie",
  224.             "@(#) All rights reserved"
  225.         };
  226. # endif
  227.  
  228.         char *MonthNames[] = {
  229.             "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  230.             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
  231.             NULL};
  232.         char *DowNames[] = {
  233.             "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
  234.             NULL};
  235.         char *ProgramName;
  236.         int LineNumber;
  237.         time_t TargetTime;
  238.  
  239. # if DEBUGGING
  240.         int DebugFlags;
  241.         char *DebugFlagNames[] = {    /* sync with #defines */
  242.             "ext", "sch", "proc", "pars", "load", "misc", "test",
  243.             NULL};    /* NULL must be last element */
  244. # endif /* DEBUGGING */
  245.  
  246. #else /* !MAIN_PROGRAM */
  247.  
  248.         extern char    *MonthNames[];
  249.         extern char    *DowNames[];
  250.         extern char    *ProgramName;
  251.         extern int    LineNumber;
  252.         extern time_t    TargetTime;
  253. # if DEBUGGING
  254.         extern int    DebugFlags;
  255.         extern char    *DebugFlagNames[];
  256. # endif /* DEBUGGING */
  257. #endif /* MAIN_PROGRAM */
  258.  
  259.  
  260. #endif    /* _CRON_FLAG */
  261.